package main

import "fmt"

func main() {
	res := sum(10, 20)
	fmt.Println(res)

	fmt.Println(sum2(10, 20))
}

// defer 延迟 --->等待关闭链接、资源释放
func sum(n1 int, n2 int) int {
	defer fmt.Println("ok1 n1=", n1) //3
	defer fmt.Println("ok1 n2=", n2) //2
	res := n1 + n2
	fmt.Println("ok3 res=", res) //1
	return res
}

func sum2(n1 int, n2 int) int {
	defer fmt.Println("ok1 n1=", n1)
	defer fmt.Println("ok1 n2=", n2)
	n1++
	n2++
	res := n1 + n2
	fmt.Println("ok3 res=", res)
	return res
}
